﻿using System.Reflection;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace Dsl.Ped.Common.Helpers
{
    /// <summary>
    /// Helper methods for the <see cref="ImageSource"/>
    /// </summary>
    public class ImageSourceHelper
    {
        /// <summary>
        /// Get default <see cref="ImageSource"/> of the given <see cref="imageUri"/>.
        /// Find the default <see cref="ImageSource"/> in the assembly of a name called <see cref="assemblyName"/>
        /// </summary>
        /// <param name="imageUri">Image URI insie the assembly of a name <see cref="assemblyName"/></param>
        /// <param name="assemblyName">Name of the assembly where there is a default image</param>
        /// <returns><see cref="ImageSource"/> from the <see cref="Assembly"/> of a name <see cref="assemblyName"/> located on the Uri <see cref="imageUri"/></returns>
        public static ImageSource GetDefaultImageSource(string imageUri, string assemblyName)
        {
            try
            {
                var defaultImage = UriHelper.GetApplicationResource(assemblyName, imageUri);
                var defaultImageSource = new BitmapImage(defaultImage);

                return defaultImageSource;
            }
            catch
            {
                return null;
            }
        }
    }
}
